"""
翻译工具类
pip install pygtrans
"""

from pygtrans import Translate, Null


# 英译汉
def english_2_chinese(text: str):
    client = Translate()
    content = client.translate(text, source='en', target='zh-CN')
    if isinstance(content, Null):
        print("翻译失败")
    else:
        return content.translatedText


# 汉译英
def chinese_2_english(text: str):
    client = Translate()
    content = client.translate(text, source='zh-CN', target='en')
    if isinstance(content, Null):
        print("翻译失败")
    else:
        return content.translatedText


if __name__ == '__main__':
    print(english_2_chinese('hello'))
    print(chinese_2_english("你好"))
